import {  ref } from 'vue'
import {EnumViewType, aspectType} from "@renderer/assets/types";
import { sendSocketIoMsg } from "@renderer/api/request";

export const useWatchStackAspect = () => {
  const getNew = (msg) => {
    sendSocketIoMsg(msg)
  }

  const aspects = ref<{
    stack: aspectType
  }>({
    stack: {
      width: 0,
      height: 0
    }
  })
  const setAspect = (args: aspectType) => {
    const { width, height } = args
    aspects.value[EnumViewType.stack] = {
      width,
      height
    }

    const msg = {
      viewType: EnumViewType.stack,
      opType: 'getImg',
      size: {
        width,
        height
      }
    }
    getNew(msg)
  }
  return {
    aspects,
    setAspect
  }
}

export const useWatchMprAspectChange = (onMprSizeGotCb) => {

  const mprAspects = ref({
    ax: null,
    sag: null,
    cor: null
  })

  const setAspect = (type: EnumViewType, { width, height }: aspectType) => {
    mprAspects.value[type] = {
      width,
      height
    }
    if (mprAspects.value[EnumViewType.ax] && mprAspects.value[EnumViewType.cor] && mprAspects.value[EnumViewType.sag]) {
      console.log('aspect change');
      onMprSizeGotCb(mprAspects.value)
    }
  }


  return {
    mprAspects,
    setAspect
  }
}
